package cn.agiledata.bank.transaction.audit.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import cn.agiledata.bank.account.service.AccountSummary;
import cn.agiledata.bank.audit.service.AuditRuleService;
import cn.agiledata.bank.audit.service.AuditService;
import cn.agiledata.bank.common.util.Constant;
import cn.agiledata.bank.common.util.WeatherUtil;
import cn.agiledata.bank.hibernateBean.AuditOperandType;
import cn.agiledata.bank.hibernateBean.Operator;
import cn.agiledata.bank.hibernateBean.RecentAuditOperation;
import cn.agiledata.bank.transaction.audit.service.EsPrePayTransService;
import com.vnv.infrastructure.action.IPBBaseAction;
import com.vnv.infrastructure.logic.IPBAppFactory;

public class EsPrePayTransAuditAction extends IPBBaseAction {
	private static Log logger = LogFactory.getLog(IPBBaseAction.class);

	private AuditService getAuditService() {
		return (AuditService) IPBAppFactory.getObj("auditService");
	}

	private EsPrePayTransService getEsPrePayTransService() {
		return (EsPrePayTransService) IPBAppFactory
				.getObj("esPrePayTransService");
	}

	private AuditRuleService getAuditRuleService() {
		return (AuditRuleService) IPBAppFactory.getObj("auditRuleService");
	}

	public ActionForward preProcess(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		// 获得审核对象类型数组
		AuditOperandType[] aot = getAuditRuleService().getAuditOperandTypes(
				false);
		// 获得当前操作员
		AccountSummary accountsummary = WeatherUtil
				.getLoingInfoFromSession(request);
		Operator operator = accountsummary.getOperatorByIdInstance(String
				.valueOf(accountsummary.getOperatorCode()));
		// 获得审核对象总数
		long sumOfAuditOperand = getAuditService()
				.getAuthoritativeRecentAuditOperationsTotal(aot, operator);
		// 获得审核对象数组
		Long beginIndex = new Long(0);
		RecentAuditOperation[] raos = getAuditService()
				.getAuthoritativeRecentAuditOperations(aot, operator,
						beginIndex.intValue(), Constant.PAGESIZE.intValue());

		// 获得交易对象列表
		List eppts = new ArrayList();
		for (int i = 0; i < raos.length; i++) {
			eppts.add(getEsPrePayTransService().getEsPrePayTransById(
					raos[i].getAuditOperandId().longValue()));
		}
		
		request.setAttribute("sumOfAuditOperand", String.valueOf(sumOfAuditOperand));
		request.setAttribute("eppts", eppts);

		return mapping.findForward("EsPrePayTransList");

	}
}